package com.ruoyi.web.controller.tools;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.tools.ToolsEssay;
import com.ruoyi.system.service.tools.IToolsEssayService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短文Controller
 * 
 * @author huangd
 * @date 2022-12-07
 */
@RestController
@RequestMapping("/tools/essay")
public class ToolsEssayController extends BaseController {
	@Autowired
	private IToolsEssayService toolsEssayService;

	/**
	 * 查询短文列表
	 */
	@PreAuthorize("@ss.hasPermi('tools:essay:list')")
	@GetMapping("/list")
	public TableDataInfo list(ToolsEssay toolsEssay) {
		startPage();
		List<ToolsEssay> list = toolsEssayService.selectToolsEssayList(toolsEssay);
		return getDataTable(list);
	}

	/**
	 * 导出短文列表
	 */
	@PreAuthorize("@ss.hasPermi('tools:essay:export')")
	@Log(title = "短文", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, ToolsEssay toolsEssay) {
		List<ToolsEssay> list = toolsEssayService.selectToolsEssayList(toolsEssay);
		ExcelUtil<ToolsEssay> util = new ExcelUtil<ToolsEssay>(ToolsEssay.class);
		util.exportExcel(response, list, "短文数据");
	}

	/**
	 * 获取短文详细信息
	 */
	@PreAuthorize("@ss.hasPermi('tools:essay:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(toolsEssayService.selectToolsEssayById(id));
	}

	/**
	 * 新增短文
	 */
	@PreAuthorize("@ss.hasPermi('tools:essay:add')")
	@Log(title = "短文", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody ToolsEssay toolsEssay) {
		return toAjax(toolsEssayService.insertToolsEssay(toolsEssay));
	}

	/**
	 * 修改短文
	 */
	@PreAuthorize("@ss.hasPermi('tools:essay:edit')")
	@Log(title = "短文", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody ToolsEssay toolsEssay) {
		return toAjax(toolsEssayService.updateToolsEssay(toolsEssay));
	}

	/**
	 * 删除短文
	 */
	@PreAuthorize("@ss.hasPermi('tools:essay:remove')")
	@Log(title = "短文", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(toolsEssayService.deleteToolsEssayByIds(ids));
	}
}
